package com.ruoyi.config;


import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.domain.idclass.TablesViewId;
import com.ruoyi.generator.domain.views.Tables;
import com.ruoyi.quartz.domain.SysJob;
import com.ruoyi.quartz.domain.SysJobLog;
import com.ruoyi.system.domain.*;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.spring.SpringCacheManager;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;

@Order
@Configuration
public class IgniteConfig {


    @Bean
    public Ignite igniteInstance() {

        IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
        igniteConfiguration.setIgniteInstanceName("springDataNode");
        igniteConfiguration.setPeerClassLoadingEnabled(true);

//        CacheConfiguration sysConfigCache = new CacheConfiguration("SysConfigCache");
//        sysConfigCache.setAtomicityMode(TRANSACTIONAL);
//        sysConfigCache.setIndexedTypes(Long.class, SysConfig.class);
//
//        CacheConfiguration sysDeptCache = new CacheConfiguration("SysDeptCache");
//        sysDeptCache.setAtomicityMode(TRANSACTIONAL);
//        sysDeptCache.setIndexedTypes(Long.class, SysDept.class);
//   //     sysDeptCache.setWriteThrough(true);
//
//        CacheConfiguration sysDictDataCache = new CacheConfiguration("SysDictDataCache");
//        sysDictDataCache.setAtomicityMode(TRANSACTIONAL);
//        sysDictDataCache.setIndexedTypes(Long.class, SysDept.class);
//    //    sysDictDataCache.setWriteThrough(true);
//
//
//        CacheConfiguration sysDictTypeCache = new CacheConfiguration("SysDictTypeCache");
//        sysDictTypeCache.setAtomicityMode(TRANSACTIONAL);
//        sysDictTypeCache.setIndexedTypes(Long.class, SysDictType.class);
//      //  sysDictTypeCache.setWriteThrough(true);
//
//
//        CacheConfiguration sysLogininforCache = new CacheConfiguration("SysLogininforCache");
//        sysLogininforCache.setAtomicityMode(TRANSACTIONAL);
//        sysLogininforCache.setIndexedTypes(Long.class, SysLogininfor.class);
//     //   sysLogininforCache.setWriteThrough(true);
//
//        CacheConfiguration sysMenuCache = new CacheConfiguration("SysMenuCache");
//        sysMenuCache.setAtomicityMode(TRANSACTIONAL);
//        sysMenuCache.setIndexedTypes(Long.class, SysDictType.class);
//    //    sysMenuCache.setWriteThrough(true);
//
//        CacheConfiguration sysNoticeCache = new CacheConfiguration("SysNoticeCache");
//        sysNoticeCache.setAtomicityMode(TRANSACTIONAL);
//        sysNoticeCache.setIndexedTypes(Long.class, SysNotice.class);
//    //    sysNoticeCache.setWriteThrough(true);
//
//        CacheConfiguration sysOperLogCache = new CacheConfiguration("SysOperLogCache");
//        sysOperLogCache.setAtomicityMode(TRANSACTIONAL);
//        sysOperLogCache.setIndexedTypes(Long.class, SysOperLog.class);
//    //    sysOperLogCache.setWriteThrough(true);
//
//        CacheConfiguration sysPostCache = new CacheConfiguration("SysPostCache");
//        sysPostCache.setAtomicityMode(TRANSACTIONAL);
//        sysPostCache.setIndexedTypes(Long.class, SysPost.class);
//      //  sysPostCache.setWriteThrough(true);
//
//        CacheConfiguration sysRoleDeptCache = new CacheConfiguration("SysRoleDeptCache");
//        sysRoleDeptCache.setAtomicityMode(TRANSACTIONAL);
//        sysRoleDeptCache.setIndexedTypes(Long.class, SysRoleDept.class);
//    //    sysRoleDeptCache.setWriteThrough(true);
//
//        CacheConfiguration sysRoleMenuCache = new CacheConfiguration("SysRoleMenuCache");
//        sysRoleMenuCache.setAtomicityMode(TRANSACTIONAL);
//        sysRoleMenuCache.setIndexedTypes(Long.class, SysRoleMenu.class);
//    //    sysRoleMenuCache.setWriteThrough(true);
//
//
//        CacheConfiguration sysRoleCache = new CacheConfiguration("SysRoleCache");
//        sysRoleCache.setAtomicityMode(TRANSACTIONAL);
//        sysRoleCache.setIndexedTypes(Long.class, SysRole.class);
//     //   sysRoleCache.setWriteThrough(true);
//
//        CacheConfiguration sysUserPostCache = new CacheConfiguration("SysUserPostCache");
//        sysUserPostCache.setAtomicityMode(TRANSACTIONAL);
//        sysUserPostCache.setIndexedTypes(Long.class, SysUserPost.class);
//     //   sysUserPostCache.setWriteThrough(true);
//
        CacheConfiguration sysUserCache = new CacheConfiguration("SysUserCache");
        sysUserCache.setAtomicityMode(TRANSACTIONAL);
        sysUserCache.setIndexedTypes(Long.class, SysUser.class);
        //  sysUserCache.setWriteThrough(true);
//
//        CacheConfiguration sysUserRoleCache = new CacheConfiguration("SysUserRoleCache");
//        sysUserRoleCache.setAtomicityMode(TRANSACTIONAL);
//        sysUserRoleCache.setIndexedTypes(Long.class, SysUserRole.class);
//      //  sysUserRoleCache.setWriteThrough(true);
//
//
//        CacheConfiguration genTableColumnCache = new CacheConfiguration("GenTableColumnCache");
//        genTableColumnCache.setAtomicityMode(TRANSACTIONAL);
//        genTableColumnCache.setIndexedTypes(Long.class, GenTableColumn.class);
//       // genTableColumnCache.setWriteThrough(true);
//
//        CacheConfiguration genTableCache = new CacheConfiguration("GenTableCache");
//        genTableCache.setAtomicityMode(TRANSACTIONAL);
//        genTableCache.setIndexedTypes(Long.class, GenTable.class);
//      //  genTableCache.setWriteThrough(true);
//
//        CacheConfiguration tablesViewCache = new CacheConfiguration("TablesViewCache");
//        tablesViewCache.setAtomicityMode(TRANSACTIONAL);
//        tablesViewCache.setIndexedTypes(TablesViewId.class, Tables.class);
//       // tablesViewCache.setWriteThrough(true);
//
//        CacheConfiguration sysJobLogCache = new CacheConfiguration("SysJobLogCache");
//        sysJobLogCache.setAtomicityMode(TRANSACTIONAL);
//        sysJobLogCache.setIndexedTypes(Long.class, SysJobLog.class);
//       // sysJobLogCache.setWriteThrough(true);
//
//
//        CacheConfiguration sysJobCache = new CacheConfiguration("SysJobCache");
//        sysJobCache.setAtomicityMode(TRANSACTIONAL);
//        sysJobCache.setIndexedTypes(Long.class, SysJob.class);
//      //  sysJobCache.setWriteThrough(true);
//
//
//        igniteConfiguration.setCacheConfiguration(sysConfigCache
//                ,sysDeptCache
//                ,sysDictDataCache
//                ,sysDictTypeCache
//                ,sysLogininforCache
//                ,sysMenuCache
//                ,sysNoticeCache
//                ,sysOperLogCache
//                ,sysPostCache
//                ,sysRoleDeptCache
//                ,sysRoleMenuCache
//                ,sysRoleCache
//                ,sysUserPostCache
//                ,sysUserCache
//                ,sysUserRoleCache
//                ,genTableColumnCache
//                ,genTableCache
//                ,tablesViewCache
//                ,sysJobLogCache
//                ,sysJobCache
//        );

        igniteConfiguration.setCacheConfiguration(sysUserCache);

        SpringCacheManager springCacheManager = new SpringCacheManager();
        springCacheManager.setConfiguration(igniteConfiguration);

        return Ignition.start(igniteConfiguration);
    }
}
